package com.ruomeng.robot.controller;

import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.apache.http.HttpResponse;
import org.apache.http.ParseException;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ruomeng.robot.service.GoodsUpdateService;
import com.ruomeng.robot.util.HttpUtils;
import com.xiaoleilu.hutool.date.DateTime;
import com.xiaoleilu.hutool.date.DateUnit;
import com.xiaoleilu.hutool.date.DateUtil;


@Controller
public class GoodsUpdateController {

	@Autowired
    private GoodsUpdateService goodsUpdateService;
	
	@RequestMapping("/test")
	@ResponseBody
	public String  test1(HttpServletResponse response){
		
		Map<String,Object> map  = new HashMap<String,Object>();
		
		

		String fiveMinAgo =DateUtil.offsetMinute(new Date(), -5).toString("yyyy-MM-dd HH:mm");
		
		System.out.println(fiveMinAgo);
		map.put("currentTime", fiveMinAgo);
	    int count =  goodsUpdateService.checkGroupGoodsStatus(map);
		return count+"";
	}
    
	 @RequestMapping("/")
	    public String index(Map<String,Object> map){
	    	 map.put("hello","from TemplateController.helloHtml");  
	 
	       return "html/view/index";
	    }
	
	public static void main(String[] args) throws Exception {
		
		//coupon("f69d49296d4b4804869f9214df52108f","554138888496");
		yongjin();
	}
	/**佣金
	 * 
	 */
	public static void yongjin(){
		
				String host = "http://pub.alimama.com";
			    String path = "/items/search.json?q=https%3a%2f%2fdetail.tmall.com%2fitem.htm%3fid%3d548359207028";
			    String method = "GET";
			    Map<String, String> querys = new HashMap<String, String>();
			    Map<String, String> headers = new HashMap<String, String>();

			    HttpResponse response;
				try {
					response = HttpUtils.doGet(host, path, method, headers, querys);
					 System.out.println(EntityUtils.toString(response.getEntity()));
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			   
	}
	/**
	 * 优惠券
	 * @param activityId
	 * @param item_id
	 */
	public static void coupon(String activityId,String item_id) {
		String host = "https://uland.taobao.com";
	    String path = "/cp/coupon?activityId="+activityId+"&itemId="+item_id+"&qq-pf-to=pcqq.group";
	    
	    String method = "GET";
	    Map<String, String> querys = new HashMap<String, String>();
	    Map<String, String> headers = new HashMap<String, String>();

	    HttpResponse response;
		try {
			response = HttpUtils.doGet(host, path, method, headers, querys);
			 System.out.println(EntityUtils.toString(response.getEntity()));
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
}
